/*
 * @Date: 2025-06-11 09:07:24
 * @LastEditors: lyx
 * @LastEditTime: 2025-06-16 10:09:01
 * @FilePath: \blog\astro.config.mjs
 * @Description: 
 */
// @ts-check
import { defineConfig } from 'astro/config';
import tailwindcss from '@tailwindcss/vite';
import tailwind from "@astrojs/tailwind";
import icon from 'astro-icon';
import mdx from "@astrojs/mdx";
import rehypeAutolinkHeadings from "rehype-autolink-headings";
import rehypeSlug from "rehype-slug";
import { fromHtmlIsomorphic } from "hast-util-from-html-isomorphic";
import rehypeColorChips from "rehype-color-chips";
import remarkAlerts from "remark-alerts";
import remarkMath from "remark-math";
import rehypeKatex from "rehype-katex";
import rehypeComponents from "rehype-components";
import remarkDirective from "remark-directive";
import { remarkReadingTime } from "./src/plugins/remark-reading-time.js";
import { remarkModifiedTime } from "./src/plugins/remark-modified-time.js";
import { remarkExcerpt } from "./src/plugins/remark-excerpt.js";
import { remarkLinkLawlighty } from "./src/plugins/remark-link-lawlighty.js";
import remarkDirectiveNode from "./src/plugins/remark-directive-node.js";
import GithubCardComponent from "./src/plugins/rehype-component-github-card.js";
import expressiveCode, { pluginFramesTexts } from "astro-expressive-code";
import sitemap from '@astrojs/sitemap';

pluginFramesTexts.overrideTexts(undefined, {
  copyButtonCopied: "复制成功",
});
// https://astro.build/config
export default defineConfig({
  vite: {
    plugins: [
      tailwindcss(),
      tailwind()
    ]
  },
  // 这边需要替换成真实的
  site: "https://blog.lawlighty.top/",
  integrations: [
    // tailwind(),
    sitemap(),
    expressiveCode({
      styleOverrides: {
        codeBackground: ({ theme }) => {
          return theme.type == "dark" ? "#24292e" : "#e6eaef";
        },
        frames: {
          frameBoxShadowCssValue: "none",
          inlineButtonBorder: "none",
          inlineButtonBackgroundHoverOrFocusOpacity: "0",
        },
      },
    }),

    icon(),
    mdx({
      // 继承自 Markdown 的 `syntaxHighlight`

      // Markdown `remarkPlugins` 被忽略，
      // 只启用 `remarkPlugin2`。
      // remarkPlugins: [remarkPlugin2],
      // `gfm` 被重写为 `false`
      // gfm: false,
    }),
  ],
  markdown: {
    shikiConfig: {
      themes: {
        light: "github-light",
        dark: "github-dark",
      },
    },
    remarkPlugins: [remarkAlerts, remarkMath, remarkReadingTime, remarkModifiedTime, remarkDirective, remarkDirectiveNode, remarkExcerpt, remarkLinkLawlighty],
    rehypePlugins: [
      rehypeKatex,
      // @ts-ignore
      rehypeColorChips,
      rehypeSlug,
      [
        rehypeComponents,
        {
          components: {
            github: GithubCardComponent,
          },
        },
      ],
      [
        rehypeAutolinkHeadings,
        {
          content: fromHtmlIsomorphic(
            '<svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="20" height="20" aria-hidden="true"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg>',
            { fragment: true }
          ).children,
          headingProperties: {
            class: "anchor",
          },
          properties: {
            ariaHidden: "true",
            tabIndex: -1,
            class: "link-anchor",
          },
        },
      ],
    ],
  },
});